/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AltaUsuario.java
 *
 * Created on 16-jul-2011, 18:32:14
 */
package ventanas;

import conexiones.AdministradorDeConexiones;
import dao.PerfilesDao;
import dao.UsuariosDao;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import modelo.Perfil;
import modelo.Usuario;

/**
 *
 * @author Matias Garcia
 */
public class AltaUsuario extends javax.swing.JDialog {
    public static Connection conn = null;
    public static DefaultComboBoxModel modeloUsuarios;
    
    //Indica si acepto o no crear un perfil en caso de ser false, la ventana AltaDeUsuario se cierra 
    public static boolean cerrarSinPerfil;
    /** Creates new form AltaUsuario */
    public AltaUsuario(java.awt.Dialog parent, boolean modal) {
        super(parent, modal);
        initComponents();
        modeloUsuarios =(DefaultComboBoxModel) cBoxPerfiles.getModel();
        listarPerfiles();
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelBotones = new javax.swing.JPanel();
        btnGuardar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        panelDatosPersona = new javax.swing.JPanel();
        lblNombre = new javax.swing.JLabel();
        lblApellido = new javax.swing.JLabel();
        lblDireccion = new javax.swing.JLabel();
        lblTelefono = new javax.swing.JLabel();
        lblCelular = new javax.swing.JLabel();
        lblEmail = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        txtApellido = new javax.swing.JTextField();
        txtDireccion = new javax.swing.JTextField();
        txtTelefono = new javax.swing.JTextField();
        txtCelular = new javax.swing.JTextField();
        txtEmail = new javax.swing.JTextField();
        lblAsteriscoNombre = new javax.swing.JLabel();
        lblAsteriscoApellido = new javax.swing.JLabel();
        lblMensaje = new javax.swing.JLabel();
        panelDatosUsuario = new javax.swing.JPanel();
        lblNombreUsuario = new javax.swing.JLabel();
        lblContraseña = new javax.swing.JLabel();
        txtUsuario = new javax.swing.JTextField();
        lblAsteriscoNombreUsuario = new javax.swing.JLabel();
        lblAsteriscoContrasena = new javax.swing.JLabel();
        txtContrasena = new javax.swing.JPasswordField();
        lblPerfil = new javax.swing.JLabel();
        cBoxPerfiles = new javax.swing.JComboBox();
        lblAsteriscoApellido1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Alta de Usuario");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        panelBotones.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        panelBotones.setPreferredSize(new java.awt.Dimension(464, 49));

        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        jButton1.setText("Cancelar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelBotonesLayout = new javax.swing.GroupLayout(panelBotones);
        panelBotones.setLayout(panelBotonesLayout);
        panelBotonesLayout.setHorizontalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotonesLayout.createSequentialGroup()
                .addGap(83, 83, 83)
                .addComponent(btnGuardar)
                .addGap(82, 82, 82)
                .addComponent(jButton1)
                .addContainerGap(63, Short.MAX_VALUE))
        );
        panelBotonesLayout.setVerticalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotonesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnGuardar)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelDatosPersona.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        lblNombre.setText("Nombre:");

        lblApellido.setText("Apellido:");

        lblDireccion.setText("Dirección:");

        lblTelefono.setText("Teléfono:");

        lblCelular.setText("Celular:");

        lblEmail.setText("E-mail:");

        lblAsteriscoNombre.setForeground(new java.awt.Color(255, 51, 0));
        lblAsteriscoNombre.setText("*");

        lblAsteriscoApellido.setForeground(new java.awt.Color(255, 51, 0));
        lblAsteriscoApellido.setText("*");

        lblMensaje.setForeground(new java.awt.Color(255, 0, 0));
        lblMensaje.setText("(*) Campos obligatorios");

        javax.swing.GroupLayout panelDatosPersonaLayout = new javax.swing.GroupLayout(panelDatosPersona);
        panelDatosPersona.setLayout(panelDatosPersonaLayout);
        panelDatosPersonaLayout.setHorizontalGroup(
            panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDatosPersonaLayout.createSequentialGroup()
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelDatosPersonaLayout.createSequentialGroup()
                        .addGap(61, 61, 61)
                        .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblTelefono)
                            .addComponent(lblCelular)
                            .addComponent(lblEmail)
                            .addComponent(lblDireccion)
                            .addComponent(lblApellido)
                            .addComponent(lblNombre))
                        .addGap(10, 10, 10)
                        .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtDireccion, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
                            .addComponent(txtTelefono, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
                            .addComponent(txtCelular, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
                            .addComponent(txtNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
                            .addComponent(txtApellido, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
                            .addComponent(txtEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)))
                    .addGroup(panelDatosPersonaLayout.createSequentialGroup()
                        .addGap(148, 148, 148)
                        .addComponent(lblMensaje)))
                .addGap(5, 5, 5)
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblAsteriscoApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAsteriscoNombre))
                .addGap(63, 63, 63))
        );
        panelDatosPersonaLayout.setVerticalGroup(
            panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDatosPersonaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNombre)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAsteriscoNombre))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblApellido)
                    .addComponent(txtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAsteriscoApellido))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDireccion)
                    .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTelefono)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCelular)
                    .addComponent(txtCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEmail)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addComponent(lblMensaje)
                .addContainerGap())
        );

        panelDatosUsuario.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        panelDatosUsuario.setPreferredSize(new java.awt.Dimension(464, 75));

        lblNombreUsuario.setText("Nombre Usuario:");

        lblContraseña.setText("Contraseña:");

        lblAsteriscoNombreUsuario.setForeground(new java.awt.Color(255, 51, 0));
        lblAsteriscoNombreUsuario.setText("*");

        lblAsteriscoContrasena.setForeground(new java.awt.Color(255, 51, 0));
        lblAsteriscoContrasena.setText("*");

        lblPerfil.setText("Perfil:");

        cBoxPerfiles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cBoxPerfilesActionPerformed(evt);
            }
        });

        lblAsteriscoApellido1.setForeground(new java.awt.Color(255, 51, 0));
        lblAsteriscoApellido1.setText("*");

        javax.swing.GroupLayout panelDatosUsuarioLayout = new javax.swing.GroupLayout(panelDatosUsuario);
        panelDatosUsuario.setLayout(panelDatosUsuarioLayout);
        panelDatosUsuarioLayout.setHorizontalGroup(
            panelDatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDatosUsuarioLayout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(panelDatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblPerfil)
                    .addComponent(lblNombreUsuario)
                    .addComponent(lblContraseña))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(cBoxPerfiles, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtContrasena)
                    .addComponent(txtUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblAsteriscoNombreUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAsteriscoContrasena, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAsteriscoApellido1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(59, Short.MAX_VALUE))
        );
        panelDatosUsuarioLayout.setVerticalGroup(
            panelDatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDatosUsuarioLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelDatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNombreUsuario)
                    .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAsteriscoNombreUsuario))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtContrasena, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAsteriscoContrasena)
                    .addComponent(lblContraseña))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPerfil)
                    .addComponent(cBoxPerfiles, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAsteriscoApellido1))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelDatosPersona, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelBotones, javax.swing.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)
            .addComponent(panelDatosUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelDatosPersona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelDatosUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelBotones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-394)/2, (screenSize.height-438)/2, 394, 438);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // Cuando presiona la tecla SI el valor de confirmacionDeCierre() = 0 y se cierra la ventana
            if(confirmacionDeCierre() == 0 ){
                this.dispose();
            }
    }//GEN-LAST:event_jButton1ActionPerformed
    
     
    
    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // TODO add your handling code here:
        Usuario usuario; 
        if(!camposObligatorios()){
            try {
                conn = AdministradorDeConexiones.obtenerConexion();
                if(UsuariosDao.getInstance().verificarDisponibilidad(conn,txtUsuario.getText())){
                    int resultado;
                    resultado = JOptionPane.showConfirmDialog(this, "El usuario será dado de alta ¿Desea continuar?", "Advertencia", JOptionPane.YES_NO_OPTION);
                    if(resultado == 0 ){             
                        Perfil perfil = (Perfil) modeloUsuarios.getSelectedItem();
                        usuario = new Usuario(txtNombre.getText(),txtApellido.getText(),txtDireccion.getText(),txtTelefono.getText(),txtCelular.getText(),txtEmail.getText(),txtUsuario.getText(),txtContrasena.getText(),perfil.getCod());
                        UsuariosDao.getInstance().guardarUsuario(conn,usuario);
                        this.dispose();
                    }
                }
                else{
                    JOptionPane.showMessageDialog(this, "El nombre de usuario no esta disponible", "Error", JOptionPane.WARNING_MESSAGE);
                    txtUsuario.setText("");
                    txtUsuario.requestFocus();
                }    
            }
            catch (Exception ex) {
                    JOptionPane.showMessageDialog(this, "El usuario no fue dado de alta", "Error", JOptionPane.WARNING_MESSAGE);} 
                }
        else{
            JOptionPane.showMessageDialog(this, "Faltan cargar datos obligatorios", "Error", JOptionPane.WARNING_MESSAGE);}
           
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here: 
            if(confirmacionDeCierre() == 0 ){
                this.dispose();
            }
    }//GEN-LAST:event_formWindowClosing

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        if(cerrarSinPerfil){
            this.dispose();
        }
    }//GEN-LAST:event_formWindowOpened

    private void cBoxPerfilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cBoxPerfilesActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cBoxPerfilesActionPerformed

    /**
     * @param args the command line arguments
     */
  
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnGuardar;
    private javax.swing.JComboBox cBoxPerfiles;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel lblApellido;
    private javax.swing.JLabel lblAsteriscoApellido;
    private javax.swing.JLabel lblAsteriscoApellido1;
    private javax.swing.JLabel lblAsteriscoContrasena;
    private javax.swing.JLabel lblAsteriscoNombre;
    private javax.swing.JLabel lblAsteriscoNombreUsuario;
    private javax.swing.JLabel lblCelular;
    private javax.swing.JLabel lblContraseña;
    private javax.swing.JLabel lblDireccion;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblMensaje;
    private javax.swing.JLabel lblNombre;
    private javax.swing.JLabel lblNombreUsuario;
    private javax.swing.JLabel lblPerfil;
    private javax.swing.JLabel lblTelefono;
    private javax.swing.JPanel panelBotones;
    private javax.swing.JPanel panelDatosPersona;
    private javax.swing.JPanel panelDatosUsuario;
    private javax.swing.JTextField txtApellido;
    private javax.swing.JTextField txtCelular;
    private javax.swing.JPasswordField txtContrasena;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtTelefono;
    private javax.swing.JTextField txtUsuario;
    // End of variables declaration//GEN-END:variables

    public boolean camposObligatorios(){
        //Retorna true si alguno de los campos esta en blanco   
        return((txtNombre.getText().trim().equals("")) | (txtApellido.getText().trim().equals("")) | (txtUsuario.getText().trim().equals("")) | (txtContrasena.getText().trim().equals("")) | (cBoxPerfiles.getSelectedIndex() == -1));
     }
   
    public int confirmacionDeCierre(){
        return(JOptionPane.showConfirmDialog(this, "Los datos se perderan ¿Desea salir?", "Advertencia", JOptionPane.YES_NO_OPTION));
    }

    private void listarPerfiles() {
        ArrayList listaPerfiles = new ArrayList();
        try {
            conn = AdministradorDeConexiones.obtenerConexion();
            listaPerfiles = PerfilesDao.getInstance().getTodos(conn);
            if(!listaPerfiles.isEmpty()){
                for (int i=0; i < listaPerfiles.size(); i++) {
                    modeloUsuarios.insertElementAt(listaPerfiles.get(i), i);
                }
            }
            else{
                //Si no existe perfil da la opcion de crearlo antes, ya que un usuario no puede NO tener un perfil asignado
                if(JOptionPane.showConfirmDialog(this, "Para crear usuario debe existir un perfil ¿Desea crearlo?", "Advertencia", JOptionPane.YES_NO_OPTION) == 0){
                    //Si acepta se crea la ventana de perfiles y se muestra
                    ABMPerfiles  abmPerfil = new ABMPerfiles(this, true);
                    abmPerfil.setVisible(true);
                    listarPerfiles();
                    cerrarSinPerfil = false;
                }
                else{
                    cerrarSinPerfil = true;
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(AltaUsuario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }




}
